package com.chinasofti.tcp03;

import java.io.*;
import java.net.Socket;

//客户端
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10000);
        //获取本地文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("java423\\1.png"));
        //将图片写到服务器
        OutputStream os = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);

        int b;
        while ((b = bis.read()) != -1){
            bos.write(b);//通过网络写到服务器
        }
        bos.flush();
        //给服务器一个结束标记。告诉服务器文件传输完毕
        socket.shutdownOutput();

        //接收服务器反馈
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while((line =br.readLine()) != null){
            System.out.println(line);
        }
        bis.close();
        socket.close();

    }
}